<?php
class TiposController extends AppController {

	var $name = 'Tipos';
	var $helpers = array('Html', 'Form');

	function index() {
		$this->Tipo->recursive = 0;
		$this->set('tipos', $this->paginate());
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid Tipo.', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->set('tipo', $this->Tipo->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->Tipo->create();
			if ($this->Tipo->save($this->data)) {
				$this->Session->setFlash(__('The Tipo has been saved', true));
				$this->redirect(array('action'=>'index'));
			} else {
				$this->Session->setFlash(__('The Tipo could not be saved. Please, try again.', true));
			}
		}

		$this->set('items', $this->Tipo->Item->find('list'));
		//$this->set(compact('items'));
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid Tipo', true));
			$this->redirect(array('action'=>'index'));
		}
		if (!empty($this->data)) {
			if ($this->Tipo->save($this->data)) {
				$this->Session->setFlash(__('The Tipo has been saved', true));
				$this->redirect(array('action'=>'index'));
			} else {
				$this->Session->setFlash(__('The Tipo could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Tipo->read(null, $id);
		}
		$items = $this->Tipo->Item->find('list');
		$this->set(compact('items'));
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for Tipo', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->Tipo->del($id)) {
			$this->Session->setFlash(__('Tipo deleted', true));
			$this->redirect(array('action'=>'index'));
		}
	}

}
?>